package com.ltmonitor.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * 角色
 * @author admin
 *
 */
@Entity
@org.hibernate.annotations.Proxy(lazy = false)
@Table(name = "role")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Role extends TenantEntity {
	private static final long serialVersionUID = 3690197650654049888L;
	private long entityId;
	private String name;
	private String code; // 指定角色的编码，用于后台硬编程判断
	/**
	 * 创建者，所有者，如果share是false, 别的用户是看不到这个角色的
	 */
	private long ownerId;
	
	/**
	 * 是否给其他用户或企业使用此权限
	 */
	private boolean share;
	/**
	 * 菜单和功能权限集合
	 */
	private Set<FunctionModel> funcs = new HashSet();

	public Role() {
		createDate = new Date();
	}

	public Role(String name) {
		this.name = name;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "roleId", unique = true, nullable = false)
	public long getEntityId() {
		return this.entityId;
	}

	public String getName() {
		return this.name;
	}

	public void setEntityId(long id) {
		this.entityId = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "RoleFunc", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "sys_func_id") })
	@OrderBy("menuSort ASC")
	public Set<FunctionModel> getFuncs() {
		return this.funcs;
	}

	public void setFuncs(Set<FunctionModel> funcs) {
		this.funcs = funcs;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public boolean isShare() {
		return share;
	}

	public void setShare(boolean share) {
		this.share = share;
	}

	public long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}

}
